#coding:utf-8

from requests import get
import sys 
from time import time
#将请求的数据保存到当前文件夹中
reload(sys)
sys.setdefaultencoding('utf-8') 


def Usage():
	print "[Usage] ./requests_demo.py [URL]"

def getHTML(URL):
	html = get(URL).text
	return html

def saveFile(Fname, Fdata):
	with open(Fname, "wb") as f:
		f.write(Fdata)

def getName():
	name = str(time())
	return name 

	

if __name__ == "__main__":
	try:
		URL = sys.argv[1]
		html = getHTML(URL)
		name = getName()
		saveFile(name + ".txt", html)
		print "[INFO] Save file success."
	except:
		Usage()

